package com.kenliang.toolslib.bloom_filter;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

/**
 * @author KenLiang
 * @description:
 * @date Created in 10:43 AM 2020/7/22.
 */
public class GuavaBloomFilterTest {


    private static final int size=1000000;

    private static final double fpp =0.0001;

    private static BloomFilter<Integer> bloomFilter = BloomFilter.create(Funnels.integerFunnel(),size,fpp);


    public static void main(String[] args) {
        //插入数据
        for (int i = 0; i < 1000000; i++) {
            bloomFilter.put(i);
        }
        int count = 0;
        for (int i = 1000000; i < 2000000; i++) {
            if (bloomFilter.mightContain(i)) {
                count++;
                System.out.println(i + "误判了");
            }
        }
        System.out.println("总共的误判数:" + count);
    }
}
